package com.finger.hospservice.controller.front;

import com.finger.hospservice.service.DepartmentService;
import com.finger.hospservice.service.HospitalService;
import com.finger.hospservice.service.ScheduleService;
import com.finger.modelservice.model.hosp.Hospital;
import com.finger.modelservice.model.hosp.Schedule;
import com.finger.modelservice.result.Result;
import com.finger.modelservice.vo.hosp.DepartmentVo;
import com.finger.modelservice.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("site/hosp/hospital")
@RestController
//@CrossOrigin
public class FrontHospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    // 分页查找医院
    @GetMapping("findHospitalPage/{page}/{limit}")
    public Result findHospital(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               HospitalQueryVo hospitalQueryVo){
        // 设置显示上线的医院
        hospitalQueryVo.setStatus(1);
        Page<Hospital> hospitalList = hospitalService.findHospital(page, limit, hospitalQueryVo);
        return Result.ok(hospitalList);
    }

    // 根据医院名称做模糊查询
    @GetMapping(value = "findHospitalLikeName/{hosname}")
    public Result findHospitalLikeName(@PathVariable String hosname){

        List<Hospital> hospitalList = hospitalService.findHospitalLikeHosName(hosname);

        return Result.ok(hospitalList);
    }

    // 根据医院编号查找医院
    @GetMapping(value = "findHospitalByHoscode/{hoscode}")
    public Result findHospitalByHoscode(@PathVariable String hoscode){

        Map<String,Object> resultMap = hospitalService.findHospitalByHoscode(hoscode);

        return Result.ok(resultMap);
    }

    // 根据医院编号查找医院科室的树结构集合
    @GetMapping(value = "findDepartmentTreeFront/{hoscode}")
    public Result findDepartmentTreeFront(@PathVariable String hoscode){

        List<DepartmentVo> departmentTree = departmentService.findDepartmentTree(hoscode);

        return Result.ok(departmentTree);
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.findScheduleDetails(hoscode, depcode, workDate));
    }

    @GetMapping("auth/getScheduleById/{scheduleId}")
    public Result getScheduleById(@PathVariable String scheduleId){

        Schedule schedule = scheduleService.findScheduleById(scheduleId);

        return Result.ok(schedule);
    }




}
